import request from '@/utils/request'
import { parseStrEmpty } from '@/utils/ruoyi'

// 查询商品列表
export function listProduct(query) {
    return request({
        url: '/product/listProductByPages',
        method: 'get',
        params: query
    })
}

// 根据商品id获取商品信息
export function getProductById(productId) {
    return request({
        url: '/product/' + parseStrEmpty(productId),
        method: 'get'
    })
}

//新增商品
export function addProduct(data) {
    return request({
        url: '/product/addProduct',
        method: 'post',
        data: data
    })
}

//修改商品
export function editProduct(data) {
    return request({
        url: '/product/editProduct',
        method: 'put',
        data: data
    })
}

//下架商品
export function downProduct(productId, shelfStatus) {
    const data = {
        productId,
        shelfStatus
    }
    return request({
        url: '/product/downProduct',
        method: 'put',
        data: data
    })
}

// 查询分类类型列表
export function treeSort() {
    return request({
        url: '/sort/listSorts',
        method: 'get'
    })
}

// 查询分类类型列表
export function listSortAll() {
  return request({
    url: '/sort/listSortAll',
    method: 'get'
  })
}
//查询一级分类
export function firstSort() {
    return request({
        url: '/sort/listFirstSorts',
        method: 'get'
    })
}
//查询二级分类
export function secondSort() {
    return request({
        url: '/sort/listSecondSorts',
        method: 'get'
    })
}

//新增分类
export function addSort(data) {
    return request({
        url: '/sort/addSort',
        method: 'post',
        data: data
    })
}

// 商品图片上传
export function uploadProductImg(data) {
    return request({
        url: '/product/upload',
        headers: {
            'Content-Type': 'multipart/form-data'
        },
        method: 'post',
        data: data
    })
}

export function listSortPrimarys(query) {
    return request({
      url: '/sort/listSortPrimarys',
      method: 'get',
      params: query
    })
}
export function listSortSecondarys(query) {
  return request({
    url: '/sort/listSortSecondarys',
    method: 'get',
    params: query
  })
}
export function listSortThreeLevels(query) {
  return request({
    url: '/sort/listSortThreeLevels',
    method: 'get',
    params: query
  })
}


// 分类查看
export function getSortById(sortId) {
  return request({
    url: '/sort/getSortById/' + sortId,
    method: 'get'
  })
}

/** 审批通过*/
export function editApproval(sortId) {
  return request({
    url: '/sort/editApproval/' + sortId,
    method: 'put'
  })
}
/** 重新审批*/
export  function resetApproval(sortId){
  return request({
    url: '/sort/resetApproval/' + sortId,
    method: 'put'
  })
}
/** 驳回*/
export function editReject(sortId){
  return request({
    url: '/sort/editReject/' + sortId,
    method: 'put'
  })
}
